openapi: 3.0.3
info:
  title: API для корпоративной доставки еды
  version: 1.0.0
  description: API для управления заказами, меню и корпоративными клиентами службы доставки еды
  contact:
    email: support@foodcorp.com
  license:
    name: Proprietary

servers:
  - url: http://localhost:8080/api/v1
    description: Сервер разработки
  - url: https://api.foodcorp.com/v1
    description: Продакшен сервер

paths:
  /meals:
    get:
      summary: Получить список блюд
      parameters:
        - name: category
          in: query
          description: Фильтр по категории
          schema:
            type: string
        - name: vegetarian
          in: query
          description: Только вегетарианские блюда
          schema:
            type: boolean
      responses:
        '200':
          description: Список доступных блюд
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Meal'
    
    post:
      summary: Добавить новое блюдо
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MealCreate'
      responses:
        '201':
          description: Блюдо успешно создано
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Meal'

  /meals/{mealId}:
    get:
      summary: Получить информацию о блюде
      parameters:
        - name: mealId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Информация о блюде
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Meal'
        '404':
          description: Блюдо не найдено

  /orders:
    get:
      summary: Получить список заказов
      parameters:
        - name: client_id
          in: query
          description: Фильтр по ID клиента
          schema:
            type: string
        - name: status
          in: query
          description: Фильтр по статусу заказа
          schema:
            type: string
            enum: [pending, preparing, delivered, cancelled]
      responses:
        '200':
          description: Список заказов
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Order'
    
    post:
      summary: Создать новый заказ
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderCreate'
      responses:
        '201':
          description: Заказ успешно создан
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'

  /clients:
    post:
      summary: Зарегистрировать корпоративного клиента
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClientCreate'
      responses:
        '201':
          description: Клиент успешно зарегистрирован
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Client'

components:
  schemas:
    Meal:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        description:
          type: string
        category:
          type: string
        price:
          type: number
        calories:
          type: integer
        vegetarian:
          type: boolean
      example:
        id: "550e8400-e29b-41d4-a716-446655440000"
        name: "Куриный суп с лапшой"
        description: "Домашний суп с курицей и овощами"
        category: "Первые блюда"
        price: 350
        calories: 250
        vegetarian: false

    MealCreate:
      type: object
      required:
        - name
        - price
      properties:
        name:
          type: string
        description:
          type: string
        category:
          type: string
        price:
          type: number
        calories:
          type: integer
        vegetarian:
          type: boolean

    Order:
      type: object
      properties:
        id:
          type: string
          format: uuid
        client_id:
          type: string
          format: uuid
        meals:
          type: array
          items:
            $ref: '#/components/schemas/OrderItem'
        total:
          type: number
        status:
          type: string
          enum: [pending, preparing, delivered, cancelled]
        delivery_time:
          type: string
          format: date-time
      example:
        id: "98e8400-e29b-41d4-a716-446655441111"
        client_id: "77e8400-e29b-41d4-a716-446655442222"
        total: 1200
        status: "preparing"
        delivery_time: "2024-03-24T13:00:00Z"

    OrderItem:
      type: object
      properties:
        meal_id:
          type: string
          format: uuid
        quantity:
          type: integer

    OrderCreate:
      type: object
      required:
        - client_id
        - meals
      properties:
        client_id:
          type: string
          format: uuid
        meals:
          type: array
          items:
            $ref: '#/components/schemas/OrderItem'
        special_requests:
          type: string

    Client:
      type: object
      properties:
        id:
          type: string
          format: uuid
        company_name:
          type: string
        contact_name:
          type: string
        contact_phone:
          type: string
        corporate_address:
          type: string
      example:
        id: "77e8400-e29b-41d4-a716-446655442222"
        company_name: "ООО Ромашка"
        contact_name: "Иванов Иван"
        contact_phone: "+7 999 123-45-67"
        corporate_address: "ул. Пушкина, д.10"

    ClientCreate:
      type: object
      required:
        - company_name
        - contact_phone
      properties:
        company_name:
          type: string
        contact_name:
          type: string
        contact_phone:
          type: string
        corporate_address:
          type: string

  responses:
    NotFound:
      description: Запрошенный ресурс не найден
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string
                example: "Ресурс не найден"

    BadRequest:
      description: Некорректные параметры запроса
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string
                example: "Некорректные входные данные"
